<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of File
 *
 * @author minhhq
 */
class MKT_Form_File extends Zend_Form_Element_File {

    public function init() {
        parent::init();

        $upload_path = MKT_Util::getConfig("upload_path");
        $this->setDestination($upload_path);
    }

    public function receive() {
        parent::receive();

        $result = array();
        $files = $this->getFileName();
        
        if (!is_array($files)) {
            $files = array($files);
        }
        
        $now = time();
        
        foreach ($files as $file) {
            $now += 1;
            $old_file   = pathinfo($file);
            $dir_name   = $old_file['dirname'];
            $base_name  = $old_file['basename'];
            $new_file_name = "{$now}_{$base_name}";
            $new_file = $dir_name . '/' . $new_file_name;
            rename($file, $new_file);
            
            $result[] = $new_file_name;
        }
        
        return $result;
    }

}

?>
